<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>javascript objects</title>
	
	<script type="text/javascript">
	
	(function(){
		objOrientedJS();
	})();
	
	
	function objOrientedJS() {
		
		Animal = {
			createNew: function(bundle) {
				
				var animal = {};
				
				var protected = bundle || {};
				
				protected.sound = 'growl';
				
				protected.makeSound = function() {
					console.log(protected.sound);
				}
				
				animal.eat = function() {console.log('eating');}
				
				return animal;
			}
		}
	
		Cat = {
			// this will act as constructor
			createNew: function() {
				
				// create an empty build obj
				//var cat = {}; 
				//var cat = {'name': 'silvester'};
				
				var protected = {};
				
				// Inherits
				var cat = Animal.createNew(protected);
				
				protected.sound = 'miau!';
				
				cat.miau = function() {protected.makeSound();};
				
				// sound is local
				var sound = 'meow';
				
				cat.makeSound = function() {
					console.log(sound);
				};
				
				return cat;
			}	
		};
		
		tmp = {name: 'adr'};
	}
	
	function closuresExample() {
		
	}	
		
	
	function action01() {
		cat = Cat.createNew();
		cat.makeSound();
		cat.miau();
		console.log('cat', cat);
	}
	
		
	function action02() {
		var counter = function(count){
			console.log('>> setting count to ' + this.count);
			return {
				getCount: function() {
					return ++count;
				}
			};
		};
		
		mycounter = counter(10);
		console.log(mycounter.getCount());
		console.log(mycounter.getCount());
		console.log(mycounter.getCount());
	}
	
	//})();

		
		
		
	</script>

</head>



<body>
<form>
	<input type="button" value="bt01" onclick="action01()" />
	<input type="button" value="bt02" onclick="action02()" />
	<input type="button" value="bt03" onclick="" />
	<input type="button" value="bt04" onclick="" />
</form>

</body>



<script type="text/javascript">

// self executing function

</script>






</html>